package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.auto.Detection;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.Scaletab;
import com.fc.v2.service.DetectionService;
import com.fc.v2.service.ScaletabService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 待检测列表Controller
 * @ClassName: ScaletabController
 * @author cjh
 * @date 2025-01-30 12:29:49
 */
@Api(value = "待检测列表")
@Controller
@RequestMapping("/ScaletabController")
public class ScaletabController extends BaseController{
	
	private String prefix = "gen/scaletab";
	
	@Autowired
	private ScaletabService scaletabService;

	@Autowired
	private DetectionService detectionService;
	
	
	/**
	 * 待检测列表页面展示
	 * @param model
	 * @return String
	 * @author cjh
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@SaCheckPermission("gen:scaletab:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "待检测列表", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@SaCheckPermission("gen:scaletab:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,Scaletab scaletab){
		PageInfo<Scaletab> page=scaletabService.list(tablepar,scaletab) ; 
		return pageTable(page.getList(),page.getTotal());
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "待检测列表新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@SaCheckPermission("gen:scaletab:add")
	@ResponseBody
	public AjaxResult add(Scaletab scaletab){
		int b=scaletabService.insertSelective(scaletab);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 待检测列表删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "待检测列表删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@SaCheckPermission("gen:scaletab:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=scaletabService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "开始检测", notes = "开始检测")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
		Detection detection= detectionService.selectByPrimaryKey(id);
		map.put("Detection",detection);
		String selectedValue=detection.getMpe1();
        //map.put("Scaletab", scaletabService.selectByPrimaryKey(id));
		//返回检测列信息
		String path =getEditPath(selectedValue,prefix);
		// 根据不同的值决定请求的 URL

		return path;
    }

	public static String getEditPath(String selectedValue, String prefix) {
		if (selectedValue == null) {
			throw new IllegalArgumentException("selectedValue不能为null");
		}

		switch (selectedValue) {
			case "E2":
			case "F1":
				return prefix + "/editabba";
			case "F2":
			case "M1":
				return prefix + "/editaba";
			case "E6":
				return prefix + "/editabba6";
			case "A6":
				return prefix + "/editaaaa6";
			case "E10":
				return prefix + "/editabba10";
			default:
				throw new IllegalArgumentException("未知的selectedValue: " + selectedValue);
		}
	}



	/**
     * 修改保存
     */
    //@Log(title = "待检测列表修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @SaCheckPermission("gen:scaletab:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Scaletab scaletab)
    {
        return toAjax(scaletabService.updateByPrimaryKeySelective(scaletab));
    }
    
    
    /**
	 * 修改状态
	 * @param record
	 * @return
	 */
    @PutMapping("/updateVisible")
	@ResponseBody
    public AjaxResult updateVisible(@RequestBody Scaletab scaletab){
		int i=scaletabService.updateVisible(scaletab);
		return toAjax(i);
	}

    
    

	
}
